package logic

import (
	"context"
	"video/videorpc/videorpcclient"

	"video/api/internal/svc"
	"video/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type VideoAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewVideoAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VideoAddLogic {
	return &VideoAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *VideoAddLogic) VideoAdd(req *types.VideoAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.VideoRpc.VideoAdd(l.ctx, &videorpcclient.VideoAddRequest{
		Title:       req.Title,
		VideoClass:  req.VideoClass,
		Image:       req.Image,
		Info:        req.Info,
		VideoStatus: req.VideoStatus,
		UserId:      req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
